package org.apache.database.enums;

import org.apache.database.dao.Condition;

import java.util.List;

public enum SelectActionEnum{
    SELECT();
    private StringBuffer sql;

    public SelectActionEnum init(){
        this.sql =new StringBuffer();
        this.sql.append("SELECT ");
        this.sql.append(" ");
        return this;
    }

    public SelectActionEnum asField(List<String> args){
        for (int i = 0; i < args.size(); i++) {
            sql.append(args.get(i)+",");
        }
        sql.deleteCharAt(sql.length()-1);
        return this;
    }

    /**
     * 拼接查找全部
     * @param tabName
     * @param offset
     * @param size
     * @return
     */
    public String findAll(String tabName,int offset,int size){
        return sql.append(" from "+tabName)
                .append(offset==-1 || size==-1?"":" LIMIT "+offset+","+size)
                .toString();
    }
    public String findWithCondition(String tabName, Condition condition){
        return sql.append(" from "+tabName)
                .append(" "+condition.getSql())
                .toString();
    }
    public String getCount(String tabName){
        return sql.append(" count(*) from "+tabName).toString();
    }
}
